<h1>Showing invoice</h1>

<p>
  <b>Issue date:</b>
  <%=h @invoice.issue_date.strftime('%Y-%m-%d') %>
</p>

<p>
  <b>Number:</b>
  <%=h @invoice.number %>
</p>

<p>
  <% if @invoice.corrected_invoice %>
    <b>Corrects:</b>
    <%= link_to @invoice.corrected_invoice.number, @invoice.corrected_invoice %>
  <% end %></td>
</p>

<p>
  <b>Source:</b>
  <%= link_to @invoice.source.name, @invoice.source %>
</p>

<p>
  <b>Target:</b>
  <%= link_to @invoice.target.name, @invoice.target %>
</p>

<p>
  <b>Selling date:</b>
  <%=h @invoice.selling_date %>
</p>

<p>
  <b>Due date:</b>
  <%=h @invoice.due_date %>
</p>

<p>
  <b>Payment method:</b>
  <%=h @invoice.payment_method %>
</p>

<p>
  <b>Positions:</b>
  <ul>
  <% @invoice.positions.each do |position| %>
    <li>
	<% product = Product.find_by_id(position.product_id) %>
    <%= link_to product.name, product %> - <%= position.quantity %> <%= product.unit %>
	</li>
  <% end %>
  </ul>
</p>

<p>
  <b>Notes:</b>
  <%=h @invoice.notes %>
</p>

<p>
  <b>Creator:</b>
  <%=h @invoice.employee.name + " " + @invoice.employee.surname %>
</p>


<%= link_to 'Edit', edit_invoice_path(@invoice) %> |
<%= link_to 'Delete', @invoice, :confirm => 'Are you sure?', :method => :delete %> |
<%= link_to 'New corrective invoice', :id => @invoice.id, :action => 'correct' %> |
<%= link_to 'List', invoices_path %>